<script setup lang="ts">
import ArticleItem from "@/components/ArticleItem.vue";
import type {ArticleVO} from "@/types/vo/ArticleVO";
import type {LikeQuery} from "@/types/query/LikeQuery";
import {getMyLiked} from "@/apis/front/liked";

const articleList = ref<ArticleVO[]>([])

const queryParams = ref<LikeQuery>({
  pageNum: 1,
  pageSize: 10,
})

const loading = ref(false)
const noMore = ref(false)

const getData = async () => {
  const res = await getMyLiked(queryParams.value)
  articleList.value = articleList.value.concat(res.data.data.records)
  if(res.data.data.records.length < queryParams.value.pageSize!){
    noMore.value = true
  }
}
const handleLoad = async () => {
  if(noMore.value || loading.value){
    return
  }
  queryParams.value.pageNum = queryParams.value.pageNum
    ? queryParams.value.pageNum + 1
    : 1
  try {
    loading.value = true
    await getData()
  } finally {
    loading.value = false
  }
};

onMounted(async () => {
  await getData()
})
</script>

<template>
  <div class="w-full h-full flex gap-20px overflow-auto pb-20px">
    <div class="flex-1 bg-white px-20px overflow-auto ">
      <h1 class="border-b-solid border-b-#f7f8fa border-b-2">我的点赞列表</h1>
      <div class="flex-1 bg-white px-24px pt-24px pb-6px overflow-y-auto">
        <n-infinite-scroll
          style="height: 100%"
          :distance="10"
          @load="handleLoad"
          :scrollbar-props="{
            trigger: 'hover',
            size: 0,
          }"
          v-if="articleList?.length"
        >
          <div v-for="item in articleList" :key="item.id" class="item mr-6px">
            <ArticleItem :Article="item" />
          </div>
          <div class="flex justify-center">
            <div v-if="loading" class="text">加载中...</div>
            <div v-if="noMore" class="text">没有更多了 🤪</div>
          </div>
        </n-infinite-scroll>
        <div
          v-else
          class="flex-1 bg-white px-24px pt-24px pb-6px overflow-y-auto"
        >
          <n-empty description="你什么也找不到"></n-empty>
        </div>
      </div>
    </div>
    <div class="h-full flex flex-col gap-5px w-250px">
      <UserCard/>
      <RecommendCard />
    </div>
  </div  >
</template>

<style scoped>

</style>
